//
//  HYLanguageManager.m
//  XPlayer
//
//  Created by 张水 on 2023/11/13.
//

#import "HYLanguageManager.h"

static NSString *const kUserLanguageKey = @"kUserLanguageKey";

@implementation HYLanguageManager

+ (void)setCurrentLanguage:(NSString *)currentLanguage {
    //跟随手机系统
    if (currentLanguage.length == 0) {
        [self resetSystemLanguage];
        return;
    }
    //用户自定义
    [[NSUserDefaults standardUserDefaults] setValue:currentLanguage forKey:kUserLanguageKey];
    [[NSUserDefaults standardUserDefaults] setValue:@[currentLanguage] forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)currentLanguage {
    return [[NSUserDefaults standardUserDefaults] valueForKey:kUserLanguageKey];
}

//** 重置系统语言 */
+ (void)resetSystemLanguage {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserLanguageKey];
    [[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
